package cn.biz.imp;

import java.util.List;

import cn.biz.GoodsBiz;
import cn.dao.GoodsDao;
import cn.entity.Goods;

public class GoodsBizImp implements GoodsBiz {
	private GoodsDao goodsDao;

	public GoodsDao getGoodsDao() {
		return goodsDao;
	}

	public void setGoodsDao(GoodsDao goodsDao) {
		this.goodsDao = goodsDao;
	}

	/*
	 * 插入一条goods信息 成功返回一个success的字符串
	 * 
	 * @see cn.biz.GoodsBiz#insert(cn.entity.Goods)
	 */
	@Override
	public String insert(Goods goods) {
		String result = "error";
		try {
			goodsDao.insertOrUpdate(goods);
			result = "success";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	/*
	 * 插入一条goods信息 成功返回一个success的字符串
	 * 
	 * @see cn.biz.GoodsBiz#insert(cn.entity.Goods)
	 */
	@Override
	public String insertOrUpdate(Goods goods) {
		String result = "error";
		try {
			goodsDao.insertOrUpdate(goods);
			result = "success";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	/*
	 * 按照实体类 删除一条goods信息 成功返回一个success的字符串
	 * 
	 * @see cn.biz.GoodsBiz#delete(cn.entity.Goods)
	 */
	@Override
	public String delete(Goods goods) {
		String result = "error";
		try {
			goodsDao.delete(goods);
			result = "success";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	/*
	 * 按照id 删除一条goods信息 成功返回一个success的字符串
	 * 
	 * @see cn.biz.GoodsBiz#delete(cn.entity.Goods)
	 */
	@Override
	public String delete(Integer id) {
		String result = "error";
		try {
			goodsDao.delete(id);
			result = "success";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	/*
	 * 更新一条goods信息 成功返回一个success的字符串
	 * 
	 * @see cn.biz.GoodsBiz#delete(cn.entity.Goods)
	 */
	@Override
	public String update(Goods goods) {
		String result = "error";
		try {
			goodsDao.update(goods);
			result = "success";
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return result;
	}

	/*
	 * 获得全部在售的goods数据,返回一个list
	 * 
	 * @see cn.biz.GoodsBiz#delete(cn.entity.Goods)
	 */
	@Override
	public List getAll() {
		return goodsDao.getAll();
	}
	
	/*
	 * 获得全部的goods数据,返回一个list
	 * 
	 * @see cn.biz.GoodsBiz#delete(cn.entity.Goods)
	 */
	@Override
	public List<Goods> getManage() {
		return goodsDao.getManage();
	}

	/*
	 * 按照id 获得一条商品详情
	 * 
	 * @see cn.biz.GoodsBiz#delete(cn.entity.Goods)
	 */
	@Override
	public Goods getGoodsById(Integer id) {
		return goodsDao.getGoodsById(id);
	}

	@Override
	public List query(Goods goods) {
		return goodsDao.query(goods);
	}

	@Override
	public List<Goods> getGoodsBySeller(Integer id) {
		return goodsDao.getGoodsBySeller(id);
	}
	
	@Override
	public List select(Goods goods) {
		return goodsDao.select(goods);
	}
}
